package com.rd.sys.common.fileexport;

import java.io.File;

import baseproj.common.exception.BaseServiceException;

import com.rd.sys.dto.commmon.base.BaseDto;
import com.rd.sys.dto.commmon.enums.ExportEnum;

/**
 * 导出线程.
 */
public class ExportThread implements Runnable {

    /** 查询条件. */
    private BaseDto queryDto;

    /** 导出类型. */
    private ExportEnum.Type type;

    /** 导出结果文件. */
    private File exportFile;

    /**
     * Instantiates a new export thread.
     * 
     * @param type
     *            the type
     * @param queryDto
     *            the query dto
     */
    public ExportThread(ExportEnum.Type type, BaseDto queryDto) {
        this.type = type;
        this.queryDto = queryDto;
    }

    /**
     * Run.
     * 
     * @version
     */
    @Override
    public void run() {
        this.exportFile = null; // 先将文件置为null,待执行导出后赋予真正的导出文件
        try {
            this.exportFile = ExportFile.execute(type, queryDto);
        } catch (BaseServiceException e) {
            throw e;
        } catch (Exception e) {
            throw new ExportOperatorException(ExportOperatorException.THREAD_EXECUTE_FAILED_ERROR);
        }
    }

    /**
     * Gets the export file.
     * 
     * @return the export file
     */
    public File getExportFile() {
        return exportFile;
    }

    /**
     * Sets the export file.
     * 
     * @param exportFile
     *            the new export file
     */
    public void setExportFile(File exportFile) {
        this.exportFile = exportFile;
    }

}
